/*
 * @Date: 2024-02-05 11:26:10
 * @LastEditTime: 2024-05-13 09:29:18
 * @Description:
 */
import { createRouter, createWebHashHistory } from 'vue-router'
import { setThirdPartyTitle, } from '@/util/thirdParty/utils/util'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [{
      path: '/',
      name: 'home',
      meta: {
        title: '首页',
        keepAlive: true //设置页面是否需要使用缓存
      },
      component: () => import('../views/HomeView.vue'),
    },
    {
      path: '/order/list',
      name: 'orderList',
      meta: {
        title: '订单列表',
      },
      component: () => import('../views/order/list.vue'),
    },
    {
      path: '/order/otherList',
      name: 'orderOtherList',
      meta: {
        title: '订单Other列表',
      },
      component: () => import('../views/order/otherList.vue'),
    },
    {
      path: '/order/test',
      name: 'orderTest',
      meta: {
        title: '订单Other列表',
      },
      component: () => import('../views/order/test3.vue'),
    },
    {
      path: '/order/upload',
      name: 'orderUpload',
      meta: {
        title: '上传',
      },
      component: () => import('../views/order/upload.vue'),
    },
  ]
})

router.beforeEach(async (to) => {
  const title = to.meta?.title ?? ''
  // 判断是否有标题
  if (!title) {
    return
  }
  document.title = title;
  try {
    setThirdPartyTitle(title)
  } catch (e) {
    console.log('router beforeEach -> setTitle : err === ', e)
  }
})

export default router
